001 /** 002 * Created by IntelliJ IDEA. 003 * User: Wei Wang 004 * Date: Apr 1, 2003 005 * Time: 9:59:07 PM 006 */ 007 008 package EVolve.util.settings; 009 010 import EVolve.Scene; 011 import javax.swing.*; 012 import java.io.*; 013 014 public class PhaseDetectorSetting extends Setting{ 015 private static PhaseDetectorSetting instance; 016 017 public static PhaseDetectorSetting v() { 018 if (instance == null) 019 instance = new PhaseDetectorSetting(); 020 return instance; 021 } 022 023 public void save(String tags[], JTextField contents[], String filename) { 024 this.contents = contents; 025 this.tags = tags; 026 iniFilename = getFilenameWithPath(filename); 027 save(); 028 } 029 030 public void readDataFromFile(String tags[], JTextField[] contents, String filename) { 031 String line; 032 RandomAccessFile iniFile; 033 File file = new File(getFilenameWithPath(filename)); 034 if (!file.exists()) return; 035 036 try { 037 iniFile = new RandomAccessFile(file,"r"); 038 for (int i=0; i<tags.length; i++) { 039 line = iniFile.readLine(); //skip tag 040 line = iniFile.readLine(); 041 contents[i].setText(line.trim()); 042 } 043 } catch (IOException e) { 044 Scene.showErrorMessage("Unable to read setting file \""+iniFilename+"\", or" + 045 "the file is corrupted."); 046 return; 047 } catch (NumberFormatException e) { 048 Scene.showErrorMessage("Format of \""+iniFilename+"\" is incorrect."); 049 return; 050 } 051 052 } 053 054 }